package com.codeworker.dbenumdatademo.entity;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

/**
 * Description: 实体类转换器
 *
 * @author code-worker
 * @date 2021/10/10 12:33
 */
@Mapper(imports = com.codeworker.dbenumdatademo.entity.StuInfoVO.Gender.class)
public interface EntityTransform {
    EntityTransform INSTANCE = Mappers.getMapper(EntityTransform.class);

    /**
     * task: StuInfoPO转StuInfoVO
     * @author code-worker
     * @date 2021/10/10 12:38
     * @param po 数据库对象
     * @return com.codeworker.dbenumdatademo.entity.StuInfoVO
     */
    @Mapping(target = "stuGender",
            expression = "java(Gender.values()[po.getStuGender()].name())")
    StuInfoVO poToVo(StuInfoPO po);

    /**
     * task: StuInfoVO转StuInfoPO
     * @author code-worker
     * @date 2021/10/10 13:44
     * @param vo 视图层对象
     * @return com.codeworker.dbenumdatademo.entity.StuInfoPO
     */
    @Mapping(target = "stuGender",
            expression = "java(Gender.valueOf(vo.getStuGender()).ordinal()+1)")
    StuInfoPO voToPo(StuInfoVO vo);
}
